package com.sparrow.common.aoi.domain;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Area {
    /**
     * 区域id
     */
    private int areaId;
    /**
     * aoi entity map
     */
    private Map<EntityType, Map<Long, AOIEntity>> entityMap;

    public Area(int areaId) {
        this.areaId = areaId;
        this.entityMap = new ConcurrentHashMap<>();
    }

    public int getAreaId() {
        return areaId;
    }

    public void setAreaId(int areaId) {
        this.areaId = areaId;
    }

    public Map<EntityType, Map<Long, AOIEntity>> getEntityMap() {
        return entityMap;
    }

    public void setEntityMap(Map<EntityType, Map<Long, AOIEntity>> entityMap) {
        this.entityMap = entityMap;
    }

    public void removeEntity(AOIEntity aoiEntity) {
       removeEntity(aoiEntity.getEntityType(), aoiEntity.getAOIId());
    }

    public void removeEntity(EntityType entityType, long id) {
        Map<Long, AOIEntity> map = entityMap.get(entityType);
        if (map == null) {
            return;
        }
        map.remove(id);
    }

    public void addEntity(AOIEntity aoiEntity) {
        Map<Long, AOIEntity> map = entityMap.computeIfAbsent(aoiEntity.getEntityType(), k -> new ConcurrentHashMap<Long, AOIEntity>());
        map.put(aoiEntity.getAOIId(), aoiEntity);
    }
}
